home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1991: Code Warrior / bincue / Code Warrior.bin / Developer Essentials / DTS Sample Code / Snippets / Snippets Aug '91 / KeepMeAround ƒ / KeepMeAround.c next >
Encoding:
C/C++ Source or Header  |  1991-09-09  |  1.9 KB  |  65 lines  |  [TEXT/MPS ]

  1. /* Code to keep an INIT file opened at boot time around all the time, à la
  2.    SuitCase II et al. */
  3.  
  4. #include <types.h>
  5. #include <memory.h>
  6. #include <sysequ.h>
  7. #include <osutils.h>
  8. #include <traps.h>
  9.  
  10. typedef struct _res_map res_map;
  11. typedef struct _res_map *res_map_ptr;
  12. typedef struct _res_map **res_map_handle;
  13.  
  14. struct _res_map {
  15. long            void1;        /* Reserved */
  16. long            void2;        /* Reserved */
  17. long            void3;        /* Reserved */
  18. long            void4;        /* Reserved */
  19. res_map_handle    next_map;    /* Handle of next resource map */
  20. short            refNum;        /* fRefNum for this file */
  21. short            fileAttrs;    /* Resource file attributes for this file */
  22. short            tlOffset;    /* Type List Offset from beginning of map */
  23. short            nlOffset;    /* Name List Offset from beginning of map */
  24. };
  25.  
  26. pascal void FakeCloseResFile(refNum)
  27. short    refNum;
  28. #pragma unused (refNum);
  29. {
  30.     res_map_handle    *legal_TopMapHndl = TopMapHndl;
  31.     long            *legal_Scratch8 = Scratch8;
  32.     res_map_handle    the_map;
  33.  
  34.     the_map = *((res_map_handle *)TopMapHndl);
  35.     *legal_TopMapHndl = (*the_map)->next_map;
  36.     DisposHandle((Handle)the_map);
  37.     NSetTrapAddress(*legal_Scratch8, _CloseResFile, ToolTrap);
  38. }
  39.  
  40. keep_me_around(void)
  41. {
  42.     THz                saved_zone;
  43.     res_map_handle    map_copy;
  44.     res_map_handle    curr_map;
  45.     res_map_handle    *legal_TopMapHndl = TopMapHndl;
  46.     long            *legal_Scratch8 = Scratch8;
  47.  
  48. /* The next few lines make a copy of the top resource map in the System Heap */
  49.     saved_zone = GetZone();
  50.     SetZone(*(THz *)SysZone);
  51.     map_copy = *((res_map_handle *)TopMapHndl);
  52.     HandToHand((Handle *)&map_copy);
  53.     SetZone(saved_zone);
  54. /* The next few lines wipe out the original handle and stick the copy at the END
  55.    of the resource chain. */
  56.     curr_map = (*map_copy)->next_map;
  57.     while (curr_map != *(res_map_handle *)SysMapHndl)
  58.         curr_map = (*curr_map)->next_map;
  59.     (*map_copy)->next_map = (*curr_map)->next_map;
  60.     (*curr_map)->next_map = map_copy;
  61.     *legal_Scratch8 = NGetTrapAddress(_CloseResFile, ToolTrap);
  62.     NSetTrapAddress((long)&FakeCloseResFile, _CloseResFile, ToolTrap);
  63. }
  64.  
  65.